const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
      active:'随意',
      page: 1,
      finished: false,
      newcomerReward:[],
      vanTab:[{
        title:'全部',
        id:'随意'
      },{
        title:'预计奖励',
        id:4
      },{
        title:'待结算',
        id:1
      },{
        title:'已结算',
        id:2
      },{
        title:'无效奖励',
        id:3
      }],
      yz_basic_info:{},
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      this.setData({
        yz_basic_info:wx.getStorageSync('yz_basic_info'),
        integral:wx.getStorageSync('integral'),
        balance:wx.getStorageSync('balance')
      })
      this.getData();
    },
    getData () {
      if (this.data.finished) return;
      let baseUrl = app.getNetAddresss('plugin.newcomer-fission.frontend.controllers.list.index');
      app._getNetWork({
        url: baseUrl,
        data: {
          page: this.data.page,
          record_status: this.data.active
        },
        success: (respone) => {
          if (respone.data.result !== 1) {
            wx.showToast({
              title: respone.data.msg,
            });
            return false;
          }
          let res = respone.data.data;
          let finished = false;
          let newcomerReward = [];
          if (res.data.length === 0 || res.data.length < res.per_page || res.current_page === res.last_page) {
            finished = true;
          }
          newcomerReward = this.data.newcomerReward.concat(res.data);
          this.setData({
            finished,
            newcomerReward,
            page: ++this.data.page,
          });
        }
      });
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
      this.getData();
    },
    changeTabs(evt) {
      this.setData({
        page: 1,
        finished: false,
        active:evt.detail.name,
        newcomerReward:[]
      })
      this.getData();
    }
})